Skip to content

Conversation

@osamakader
Copy link
Contributor

The pattern .to_string().as_str() creates a temporary String that is immediately borrowed and then dropped, which is inefficient. Replace with &.to_string() for cleaner, more idiomatic code.

Changes:

  • compiler/rustc_builtin_macros/src/autodiff.rs: Simplify identifier creation
  • compiler/rustc_codegen_llvm/src/context.rs: Simplify error message formatting

The pattern .to_string().as_str() creates a temporary String that is
immediately borrowed and then dropped, which is inefficient. Replace
with &.to_string() for cleaner, more idiomatic code.

Changes:
- compiler/rustc_builtin_macros/src/autodiff.rs: Simplify identifier creation
- compiler/rustc_codegen_llvm/src/context.rs: Simplify error message formatting

Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 26, 2025
@osamakader osamakader marked this pull request as ready for review October 26, 2025 22:01
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 26, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 26, 2025

Some changes occurred in compiler/rustc_builtin_macros/src/autodiff.rs

cc @ZuseZ4

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 26, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 26, 2025

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@Kobzol
Copy link
Member

Kobzol commented Oct 27, 2025

.as_str() vs & has no performance effect here, it does the same thing.

@lcnr
Copy link
Contributor

lcnr commented Oct 27, 2025

Why is &X.to_string() more idiomatic?

I don't think this change is worth the (admittedly very small) churn

@osamakader osamakader closed this Oct 27, 2025
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants